﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using iTunesLib;

namespace iTunesNowPlaying
{
    internal class Track
    {
        string m_artist = string.Empty;
        string m_track = string.Empty;
        string m_album = string.Empty;
        string m_name = string.Empty;

        public Track()
        {

        }

        public string Artist
        {
            get { return m_artist; }
        }

        public string Title
        {
            get { return m_track; }
        }

        public string Album
        {
            get { return m_album; }
        }

        public string Name
        {
            get { return m_name; }
        }

        public void GetTrackInfo()
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\MediaPlayer\CurrentMetadata", false);
            if (key != null)
            {
                m_track = key.GetValue("Title") as string;
                m_album = key.GetValue("Album") as string;
                m_artist = key.GetValue("Author") as string;
                m_name = key.GetValue("Name") as string;
            }
            else
            {
                try
                {
                    iTunesApp app = new iTunesAppClass();
                    IITTrack track = app.CurrentTrack;
                    m_album = track.Album;
                    m_artist = track.Artist;
                    m_track = track.Name;
                }
                catch { }
            }
        }
    }
}
